package com.cmfi.dao;


import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cmfi.domain.AssembleQuality;

/**
 * Spring Data R2DBC repository for the ForkliftQuality entity.
 */
@Mapper
public interface ForkliftQualityDao  {
	
	@Select("select * from  forklift_quality order by createTime DESC limit #{start},#{itemNum}")
    List<AssembleQuality> findAllByPage(long start,long itemNum);

	@Insert("insert into forklift_quality(vinCode,partCode,partName,partType,position,username,quality,qualityCodeLevelOne"
			+ ",qualityCodeLevelTwo,qualityCodeLevelThree,description,createTime,updateTime) "
			+ " values(#{vinCode},#{partCode},#{partName},#{partType},#{position},#{username},"
			+ "#{quality},#{qualityCodeLevelOne},#{qualityCodeLevelTwo},#{qualityCodeLevelThree},#{description},#{createTime},"
			+ "#{updateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "id")//可以把自動生成的id帶過來
	void save(AssembleQuality entity);

	@Update("update forklift_quality set vinCode=#{vinCode},partCode=#{partCode},partName=#{partName},"
			+ "partType=#{partType},position=#{position},username=#{username},quality=#{quality},qualityCodeLevelOne=#{qualityCodeLevelOne},"
			+ "qualityCodeLevelTwo=#{qualityCodeLevelTwo},qualityCodeLevelThree=#{qualityCodeLevelThree},description=#{description},"
			+ "createTime=#{createTime},updateTime=#{updateTime} where id = #{id}")
	void update(AssembleQuality entity);

	@Select("select * from  forklift_quality order by createTime DESC")
    List<AssembleQuality> findAll();
	
	@Select("select count(1) from  forklift_quality")
    long count();

	@Select("select * from  forklift_quality where id=#{id}")
    AssembleQuality findById(Long id);

	@Select("select * from  forklift_quality where vinCode=#{vinCode} order by createTime DESC")
    List<AssembleQuality> findForkliftQualitiesByVinCode (String vinCode);

	@Select("select * from  forklift_quality where vinCode=#{vinCode} and position=#{position} order by createTime DESC")
    List<AssembleQuality> getForkliftQualitiesByVinCodeAndPosition (String vinCode,String position);

	@Delete("delete from forklift_quality where id = #{id}")
    void deleteById(Long id);

	@Select("select forklift_quality.vinCode,forklift_quality.position,forklift_quality.quality from forklift_quality where forklift_quality.position = #{position} order by vinCode DESC")
	List<AssembleQuality> findQualityByPosition(String position);

}
